<template>
  
  <div>
    <!-- 顶部滑动导航 -->
    <div id="slider" class="mui-slider">
      <div class="mui-scroll-wrapper mui-slider-indicator mui-segmented-control mui-segmented-control-inverted">
        <div class="mui-scroll">
          <a :class="['mui-control-item',item.id==0?'mui-active':'' ] "  v-for="(item,index) in cates" :key="index" @tap="getphotoList(item.id)">
            {{item.title}}
          </a>
        </div>
      </div>
    </div>

  <!-- 图片列表部分 -->
    <ul class="photo-list">
      <router-link v-for="(item,index) in list" :key="index" :to="'/home/photoinfo/' + item.id" tag="li">
        <img v-lazy="item.img_url">
        <div class="info">
          <h1 class="info-title">{{ item.title }}</h1>
          <div class="info-body">{{ item.zhaiyao }}</div>
        </div>
      </router-link>
    </ul>
  </div>


  
</template>

<script>
import {Toast} from 'mint-ui'
import mui from  '../../lib/mui/js/mui.js'
export default {
    data(){
      return {
        cates:[] ,  //图片分类
        list:[]
        
      }
    },
    created(){
      this.getCategory()   
      this.getphotoList(0)   //默认第一次渲染的为ID为0的全部分类
    },
    mounted(){
      mui('.mui-scroll-wrapper').scroll({
	    deceleration: 0.0005 //flick 减速系数，系数越大，滚动速度越慢，滚动距离越小，默认值0.0006
      });
    },
    methods:{
      //获取分类列表
      getCategory(){
        this.$http.get('api/getimgcategory').then(result => {
          if(result.body.status === 0){
            var cmt = {
              title:'全部',
              id:0
            }
            result.body.message.unshift(cmt)
              this.cates = result.body.message
          }
        })
      },
      // 根据分类列表ID获取对应的图片列表
      getphotoList(cateId){
          this.$http.get("api/getimages/" + cateId).then(result => {
            if (result.body.status === 0) {
              this.list = result.body.message;
            }
          });
      }
    }
}
</script>

<style lang="scss" scoped>
*{
  touch-action: pan-y;
}

.photo-list{
  list-style: none;
  padding: 5px;
  margin: 0;
  padding-bottom: 0;
  li {
    text-align: center;
    background-color: #ccc;
    position: relative;
    box-shadow: 0 0 8px #999;
    margin-bottom: 10px;
    img {
      width: 100%;
      vertical-align: middle; 
    }
    img[lazy=loading] {
      width: 40px;
      height: 300px;
      margin: auto;
    }

    .info {
      color: white;
      background-color: rgba(0, 0, 0, 0.4);
      position: absolute;
      bottom: 0;
     text-align: left;
     max-height: 84px;
      .info-title {
        font-size: 14px;
      }
      .info-body {
        font-size: 13px;
      }
    }
  }
}

</style>
